package com.abel;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by Administrator on 2017/5/5.<br/>
 * cachedThreadPool 适用于生命周期较短的异步型任务,是线程池的首选;<br/>
 * fixedThreadPool 适用于固定的并发线程;<br/>
 * singleThreadExecutor 适用于单线程;<br/>
 */
public class TaskRunable implements Runnable {
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程被调用了");
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        //        ExecutorService executorService = Executors.newCachedThreadPool();
        //        ExecutorService executorService = Executors.newFixedThreadPool(5);
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        for (int i=0;i<100;i++){
            executorService.execute(new TaskRunable());
        }
        executorService.shutdown();

    }
}
